package com.sgcc.fj.pmos.e_fj_mall.presenter;

import android.text.TextUtils;

import com.blankj.utilcode.util.ToastUtils;
import com.sgcc.fj.pmos.common.base.BasePresenter;
import com.sgcc.fj.pmos.common.bean.PowMonth;
import com.sgcc.fj.pmos.common.utils.UserManager;
import com.sgcc.fj.pmos.e_fj_mall.contract.PowersetContract;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class PowersetPresenter extends BasePresenter<PowersetContract.View> implements PowersetContract.Presenter {
    @Override
    public void getpowerList(int pageSize, boolean isLoading) {

    }
    private String convertDoubleToString(String num) {
        BigDecimal bd = new BigDecimal(num);
        return bd.setScale(3, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString();

    }

    public String getTotalTipick(Map<Integer, String> map) {

        if (map != null) {
            Set keySet = map.keySet();
            if (keySet.size() != 0) {
                String totalTipicStr = "";
                double oldPow = Double.valueOf(UserManager.getUserBean().getEnergyHis());
                if (!TextUtils.isEmpty(UserManager.getUserBean().getEnergyHis())) {
                    for (Object keyName : keySet) {
                        double nowPow = Double.valueOf(map.get(keyName));
                        if (nowPow > 1.2 * oldPow || nowPow < 0.8 * oldPow) {
                            //totalTipicStr = totalTipicStr + keyName + "月你的输入的约定量总量是" +convertDoubleToString(nowPow+"") + "MWh,与去年月均用电量悬殊较大，请确认。\n";
                            totalTipicStr="约定电量与上月用电量悬殊较大，请确认";
                        }
                    }
                } else {
                    return "";
                }
                if (!TextUtils.isEmpty(totalTipicStr)) {
                    return totalTipicStr;
                } else {
                    return "";
                }
            } else {
                return "";
            }
        } else {
            return "";
        }

    }

    public static boolean checkPowList(List<PowMonth> list) {
        boolean haveNull = false;
        for (int i = 0; i < list.size(); i++) {
            if (TextUtils.isEmpty(list.get(i).getREnergy1() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy2() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy3() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy4() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy5() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy6() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy7() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy8() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy9() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy10() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy11() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy12() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy13() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy14() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy15() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy16() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy17() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy18() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy19() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy20() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy21() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy22() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy23() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            } else if (TextUtils.isEmpty(list.get(i).getREnergy4() + "")) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            }
        }
        return haveNull;
    }
}
